package com.phoenix.sgs.faq.adapter;

import java.util.List;

import com.phoenix.sgs.faq.R;
import com.phoenix.sgs.faq.general.Skill;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.BaseAdapter;

public class SkillAdapter extends BaseAdapter {
	List<Skill> itemList;
    public Activity context;
    public LayoutInflater inflater;

    public SkillAdapter(Activity context, List<Skill> itemList) {
        super();
        this.context = context;
        this.itemList = itemList;
        this.inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

	@Override
	public int getCount() {
		return itemList.size();
	}

	@Override
	public Object getItem(int position) {
		return itemList.get(position);
	}

	@Override
	public long getItemId(int position) {
		return ((Skill)this.getItem(position)).getId();
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder holder;
		if(convertView==null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.generaldetail_skills, null);
            holder.textViewType = (TextView) convertView.findViewById(R.id.tvSkillType);
            holder.textViewName = (TextView) convertView.findViewById(R.id.tvSkillName);
            holder.textViewDescription = (TextView) convertView.findViewById(R.id.tvSkillDesc);
            holder.textViewComments = (TextView) convertView.findViewById(R.id.tvSkillComments);
            convertView.setTag(holder);
        }
        else {
            holder=(ViewHolder)convertView.getTag();
        }
		
        Skill skill = (Skill) itemList.get(position);
        holder.textViewType.setText(skill.getSkillType().getName());
        holder.textViewName.setText(skill.getName());
        holder.textViewDescription.setText(skill.getDescription());
        holder.textViewComments.setText(skill.getComments());
        return convertView;
	}
	
	public static class ViewHolder
    {
		TextView textViewType;
        TextView textViewName;
        TextView textViewDescription;
        TextView textViewComments;
    }
}
